﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Commonlib;

namespace AlbonWeb.Manager.BulletinManager
{
    public partial class BulletinShow : System.Web.UI.Page
    {
        protected readonly BLL.BulletinBLL bulletinbll = new BLL.BulletinBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request["id"] != null)
                {
                    initData(Request["id"].ToString());
                }
            }
        }

        //加载数据
        private void initData(string id)
        {
            DataTable dt=bulletinbll.getBulletinByID(id);
            repMain.DataSource = dt;
            repMain.DataBind();
        }

        //显示全部信息
        protected void showOthers_Click(object sender, EventArgs e)
        {
            showOthers.Visible = false;
            bindAllBulletin();
        }

        //换页
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            bindAllBulletin();
        }

        //绑定所有数据
        private void bindAllBulletin()
        {
            string cmdstr = "select count(*) from BulletinMessage where active=1";
            AspNetPager1.RecordCount = int.Parse(SqlHelper.ExecuteScalar(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null).ToString());
            SqlParameter[] parameters = new SqlParameter[]{
                new SqlParameter("@tablename","BulletinMessage"),
                new SqlParameter("@startIndex",AspNetPager1.StartRecordIndex),
                new  SqlParameter("@endIndex",AspNetPager1.EndRecordIndex),
                new SqlParameter("@limit"," where active=1"),
                new SqlParameter("@orderby","createDate desc")
            };
            SqlHelper.BindRepeater(repMain, SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "netpager", parameters);
        }
    }
}